package com.stoneframe.controller.manageAuthorize;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stoneframe.controller.base.BaseGenericController;
import com.stoneframe.service.BaseService;
import com.stoneframe.service.manageAuthorize.SysAuthorizeService;
import com.stoneframe.util.baseApp.AppHelper;

@Controller
@RequestMapping(value="sysPermissionPost")
public class SysPermissionPostController extends BaseGenericController {
	
	@Resource(name="sysAuthorizeService")
	private SysAuthorizeService sysAuthorizeService;

	@Override
	public BaseService getService() {
		// TODO Auto-generated method stub
		return sysAuthorizeService;
	}
	
	@RequestMapping(value="saveMember")
	@ResponseBody
	public Object saveMember(String postId,String userIds){
		logBefore(logger, className+"saveMember");
		try{
			String[] arrUserId=userIds.split(",");
			sysAuthorizeService.saveMember(3,postId,arrUserId);
			
			logAfter(logger);
			return AppHelper.successObject("保存成功。");
		}catch(Exception e){
			logger.error(e.toString(), e);
			return AppHelper.errorObject(e.getMessage());
		}
	}
	
	@RequestMapping(value="saveAuthorize")
	@ResponseBody
	public Object saveAuthorize(String postId, String moduleIds, String moduleButtonIds, String moduleColumnIds, String authorizeDataJson){
		logBefore(logger, className+"saveAuthorize");
		try{
			String[] arrModuleId=moduleIds.split(",");
			String[] arrModuleButtonId=moduleButtonIds.split(",");
			String[] arrModuleColumnId=moduleColumnIds.split(",");
			ObjectMapper objectMapper=new ObjectMapper();
			List<Map<String, Object>> authorizeDataList=objectMapper.readValue(authorizeDataJson, List.class);
			
			sysAuthorizeService.saveAuthorize(3,postId,arrModuleId,arrModuleButtonId,arrModuleColumnId,authorizeDataList);
			
			logAfter(logger);
			return AppHelper.successObject("保存成功。");
		}catch(Exception e){
			logger.error(e.getMessage(), e);
			return AppHelper.errorObject(e.getMessage());
		}
	}

}
